const express = require("express");
const bodyParser = require('body-parser')
const app = express();
require("./model/connect");
app.all("*", (req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "content-type,authorization");
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  res.header("Content-Type", "application/json;charset=utf-8");
  next();
});
app.use(bodyParser.json())
app.use(require('./token/authorization'))
app.use(require('./token/expressJwt'));
app.use((err, req, res, next) => {
  if (err.status == 401) {
    return res.status(401).send('token失效');
  }
})
app.use("/api", require("./routes/home"));
app.use("/admin", require("./routes/admin"));

app.listen(3001, () => console.log("服务器启动成功，请访问localhost"));
